//
//    Copyright (C) 2012  OinkStudio
//
//    This program is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with this program.  If not, see <http://www.gnu.org/licenses/>.

package com.marakana.obolo;

import database.DBAdapter;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;
import android.widget.TextView;

public class MenuActivity extends Activity {
	/** Called when the activity is first created. */
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.menu);

		// Inicialitza les referencias als objectes del menu.xml
		TextView newGame = (TextView) findViewById(R.id.txtNewGame);
		TextView singlePlayer = (TextView) findViewById(R.id.txtSinglePlayer);
		TextView options = (TextView) findViewById(R.id.txtOptions);
		TextView quit = (TextView) findViewById(R.id.txtQuit);

		LinearLayout mainLay = (LinearLayout) quit.getParent();

		// Afegeix el background
		//addBackground(mainLay);

		newGame.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				AlertDialog.Builder builder = new AlertDialog.Builder(MenuActivity.this);
				builder.setCancelable(true);
				builder.setIcon(R.drawable.pigdemon_question);
				builder.setTitle("Estàs segur que vols començar de nou?");
				builder.setInverseBackgroundForced(true);
				builder.setPositiveButton("Sí",
						new DialogInterface.OnClickListener() {
							@Override
							public void onClick(DialogInterface dialog,
									int which) {
								//Hace falta añadir algo para resetear o no el modo historia...
								DBAdapter dbAdapter = new DBAdapter(MenuActivity.this);
								dbAdapter.resetDB();								
								dialog.dismiss();
							}
						});
				builder.setNegativeButton("No",
						new DialogInterface.OnClickListener() {
							@Override
							public void onClick(DialogInterface dialog,
									int which) {
								dialog.dismiss();
							}
						});
				AlertDialog alert = builder.create();
				alert.show();

			}
		});

		singlePlayer.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				Intent single_player_activity = new Intent(v.getContext(),
						SinglePlayerActivity.class);
				startActivity(single_player_activity);
			}
		});

		options.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent options_activity = new Intent(v.getContext(),
						OptionsActivity.class);
				startActivity(options_activity);
			}
		});

		quit.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				finish();
			}
		});

	}
}